package com.central.comment.mq

import com.central.comment.service.CommentService
import com.central.common.model.CommentRpcDto
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.cloud.stream.annotation.StreamListener
import org.springframework.messaging.handler.annotation.Payload
import org.springframework.stereotype.Service

/**
 * @author  fly
 * @date  2021/6/1 18:54
 * @version 1.0
 */
@Service
open class SubscribableService {

    private val log: Logger = LoggerFactory.getLogger(SubscribableService::class.java)

    @Autowired
    private lateinit var commentService: CommentService

    @StreamListener(authenticate)
    fun subscribableAuthenticateService(@Payload commentRpcDto: CommentRpcDto) {

        log.info("监听到了实体 ${commentRpcDto.createBy} 的消息")
        commentService.insertComment(commentRpcDto)?.run {
            log.info("消费成功")
        }
    }
}